#pragma once

class Interface_SplashScreen_Effect_Petals
{
	class Petals_Action : public Graphic_Particle_PolicyTemplate
	{
	public:
		inline virtual void operator()(Graphic_Particle & Target)
		{
			if(Target.mPosition.y < - APP_HEIGHT * 0.7f || Target.mPosition.x > APP_WIDTH * 0.7f) 
				Target.mRespawn = true;
			else
				(Target.mLife > 0.0f)? NULL : Target.mRespawn = true;
			if(Target.mRespawn) return;
			Target.mPosition += Target.mVelocity * mfInterval;
			Target.mLife += Target.mLifeDelta * mfInterval;
			Target.mColor = ARGB(Target.mLife, 255, 255, 255);
			Target.mScale += Target.mScaleDelta * mfInterval;
			Target.mBearing += Target.mAngularVelocity * mfInterval;

			if(abs(Target.mScale.x) > 0.7f || abs(Target.mScale.y) > 1.1f)
				Target.mScaleDelta *= -1;
		}
	};

	class Petals_Initialize : public Graphic_Particle_PolicyTemplate
	{
	public:
		inline virtual void operator()(Graphic_Particle & Target)
		{
			Target.mLife = 255.0f;
			Target.mLifeDelta = -System_Utility::RandomFloat(0.0f, 30.0f);
			Target.mBearing = System_Utility::RandomFloat(0.0f, PI * 2.0f);
			Target.mVelocity.x = System_Utility::RandomFloat(40.0f, 100.0f);
			Target.mVelocity.y = System_Utility::RandomFloat(-30.0f, -150.0f);
			Target.mAngularVelocity = System_Utility::RandomFloat(0.4f, 0.5f);
		
			float Size = System_Utility::RandomFloat(0.4f, 0.9f);
			if(Target.mPosition.y > APP_HEIGHT * 0.3f)
				Target.mScale = Vector2(Size * 0.7f, Size * 1.1f) * 1.0f;
			if(Target.mPosition.y > APP_HEIGHT * 0.15f)
				Target.mScale = Vector2(Size * 0.7f, Size * 1.1f) * 0.8f;
			else
				Target.mScale = Vector2(Size * 0.7f, Size * 1.1f) * 0.6f;


			Size = System_Utility :: RandomFloat(0.0f, 1.5f);
			switch(rand() % 2)
			{
			case 0: 
				Target.mScaleDelta = Vector2(Size, 0);
				break;
			case 1:
				Target.mScaleDelta = Vector2(0, Size);
				break;
			}
		}
	};
	typedef Graphic_ParticleSystem <Petals_Initialize, Petals_Action> ParticleSystem;
	SmartPtr	<ParticleSystem>	mHandler;
	SmartPtr	<hgeSprite>			mPetalsImg;
	std::deque	<Vector2>			mSpawnPoints;

	float		mTimepassed;
public:
	Interface_SplashScreen_Effect_Petals();
	~Interface_SplashScreen_Effect_Petals();

	bool Initialize();

	void Update(const float & Interval);
	void Render();
};